﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Web.coffinegurunaru.AppLogic.Page;
using Com.Library.DB.Manager;
using Com.Library.Page;

namespace Com.Web.coffinegurunaru.manager.manager
{
	public partial class managerMethod : ManagerAjaxPage
	{
		public string[] Create(string ManagerID, string ManagerPassword, 
			string ManagerName)
		{
			int ManagerSN = ManagerModel.Create(ManagerID, ManagerPassword,
				ManagerName);

			string[] retVal = new string[10];

			if (ManagerSN > 0)
			{
				retVal[0] = ManagerSN.ToString();
				retVal[1] = ManagerID;
			}
			else
			{
				retVal[0] = ManagerSN.ToString();
				retVal[1] = "생성실패";
			}

			return retVal;
		}

		public void Modify(int ManagerSN, string ManagerPassword, string ManagerName)
		{
			ManagerModel.Modify(ManagerSN, ManagerPassword, ManagerName);
		}

		public void Manager(int ManagerSN, byte isManager)
		{
			ManagerModel.ModifyManager(ManagerSN, isManager);
		}

		public string[] GetList(int PageNo, byte PageSize)
		{
			int CntRow = 0;
			int CntTotal = 0;

			List<ManagerEntity> list = ManagerModel.GetList(PageNo, PageSize, out CntRow, out CntTotal);

			Dictionary<string, object> properties = new Dictionary<string,object>();

			ManagerEntity info = ManagerModel.GetInfo(this.WebCookies.ManagerSN, string.Empty);

			properties.Add("ManagerList", list);
			properties.Add("ManagerSN", this.WebCookies.ManagerSN);
			properties.Add("IsManager", info.IsManager);

			string[] retVal = new string[10];

			retVal[0] = ViewManager<ManagerPage>.Render("/manager/manager/managerList.ascx", properties);
			retVal[1] = CntTotal.ToString();

			return retVal;
		}

		public string[] GetListForAuth(string ManagerID, string ManagerName, int PageNo, byte PageSize)
		{
			int CntRow = 0;
			int CntTotal = 0;
			List<ManagerEntity> list = null;

			if ( ManagerID != string.Empty )
				ManagerModel.GetListByManagerID(ManagerID, PageNo, PageSize, out CntRow, out CntTotal);
			else if (ManagerName != string.Empty)
				ManagerModel.GetListByManagerName(ManagerName, PageNo, PageSize, out CntRow, out CntTotal);
			else list = ManagerModel.GetList(PageNo, PageSize, out CntRow, out CntTotal);

			

			Dictionary<string, object> properties = new Dictionary<string, object>();

			properties.Add("ManagerList", list);

			string[] retVal = new string[10];

			retVal[0] = ViewManager<ManagerPage>.Render("/manager/manager/managerList2.ascx", properties);
			retVal[1] = CntTotal.ToString();

			return retVal;
		}

		public void Remove(int ManagerSN)
		{
			ManagerModel.Remove(ManagerSN);
		}
	}
}
